<template>
	<view>
		<view class="block">
			<view class="content">
				<view class="orderinfo">
					<view class="row">
						<view class="nominal">订单名称:</view>
						<view class="text">{{orderinfo.serviceName[0]}}</view>
					</view>
					<view class="row">
						<view class="nominal">订单金额:</view>
						<view class="text">{{orderinfo.payablePrice}}元</view>
					</view>
				</view>
			</view>
		</view>
		<view class="block">
			<view class="title">
				选择支付方式
			</view>
			<view class="content">
				<view class="pay-list">
					<view class="row" @tap="paytype='alipay'">
						<view class="left">
							<image src="/static/img/alipay.png"></image>
						</view>
						<view class="center">
							支付宝支付
						</view>
						<view class="right">
							<radio :checked="paytype=='alipay'" color="#f06c7a" />
						</view>
					</view>
					<!-- <view class="row" @tap="paytype='wxpay'">
						<view class="left">
							<image src="/static/img/wxpay.png"></image>
						</view>
						<view class="center">
							微信支付
						</view>
						<view class="right">
							<radio :checked="paytype=='wxpay'" color="#f06c7a" />
						</view>
					</view> -->
					<!-- 	<view class="row" @tap="paytype='balance'">
							<view class="left">
								<image src="/static/余额.png"></image>
							</view>
							<view class="center">
								余额结算 :￥480
							</view>
							<view class="right">
								<radio :checked="paytype=='balance'" color="#f06c7a" />
							</view>
					</view> -->
				</view>
			</view>
		</view>
		<u-popup :show="show" @close="close" mode="center" @open="open">
			<view style="display: flex;flex-direction: column; justify-content: center;align-items: center;">
				<u-tooltip text="长按复制此链接到手机浏览器完成支付" size="29" :copyText="xxinfo" direction="top"></u-tooltip>
				{{xxinfo}}
			</view>
		</u-popup>
		<view class="pay">
			<view class="btn" @tap="doDeposit">立即支付</view>
			<view class="tis">
				点击立即支付，即代表您同意<view class="terms">
					《条款协议》
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		base_Url
	} from '../../../utils/Url';

	export default {
		data() {
			return {
				amount: 0,
				orderName: '',
				paytype: 'alipay', //支付类型
				orderinfo: {},
				show: false,
				xxinfo: "出淤泥而不染，濯清涟而不妖"
			};
		},
		onLoad(e) {
			this.amount = parseFloat(e.amount).toFixed(2);
			if (e) {
				console.log("支付信息2", e.item);
				const that = this
				this.$http.post('/buyrOrder/tjSearch', {
					id: e.item,
					orderStatus: 0
				}).then(res => {
					console.log('res', res);
					const aa = res.result[0]
					console.log("aa", aa);
					this.orderinfo = {
						...aa
					}
					console.log("xinxi", this.orderinfo);
					const name = this.orderinfo.serviceName[0]
					this.xxinfo = base_Url +
						`/pay/alipay2?subject=${name}&traceNo=${this.orderinfo.id}&totalAmount=${this.orderinfo.payablePrice}`

				})


			}
			uni.getStorage({
				key: 'paymentOrder',
				success: (e) => {
					if (e.data.length > 1) {
						this.orderName = '多商品合并支付'
					} else {
						this.orderName = e.data[0].name;
					}
					uni.removeStorage({
						key: 'paymentOrder'
					})
				}
			})


		},
		methods: {
			open() {
				// console.log('open');

			},
			close() {
				this.show = false
				console.log('close');
				uni.redirectTo({
					url: "/otherPage/myOrder/myOrder?index=" + 1

				})
			},
			doDeposit() {
				this.show = true
				//模板模拟支付，实际应用请调起微信/支付宝
				console.log("aa", this.orderinfo)
				// uni.showLoading({
				// 	title: '支付中...'
				// });
				setTimeout(() => {
					// uni.hideLoading();
					// uni.showToast({
					// 	title: '支付成功'
					// });
					// setTimeout(()=>{
					// 	uni.redirectTo({
					// 		url:'/pages/pay/success/success?amount='+this.amount
					// 	});
					// },300);
				}, 700)
			}
		}
	}
</script>

<style lang="scss">
	.block {
		width: 94%;
		padding: 0 3% 40upx 3%;

		.title {
			width: 100%;
			font-size: 34upx;
		}

		.content {
			.orderinfo {
				width: 100%;
				border-bottom: solid 1upx #eee;

				.row {
					width: 100%;
					height: 90upx;
					display: flex;
					align-items: center;

					.nominal {
						flex-shrink: 0;
						font-size: 32upx;
						color: #7d7d7d;
					}

					.text {
						width: 70%;
						margin-left: 10upx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						font-size: 32upx;
					}
				}
			}

			.pay-list {
				width: 100%;
				border-bottom: solid 1upx #eee;

				.row {
					width: 100%;
					height: 120upx;
					display: flex;
					align-items: center;

					.left {
						width: 100upx;
						flex-shrink: 0;
						display: flex;
						align-items: center;

						image {
							width: 80upx;
							height: 80upx;
						}
					}

					.center {
						width: 100%;
						font-size: 30upx;
					}

					.right {
						width: 100upx;
						flex-shrink: 0;
						display: flex;
						justify-content: flex-end;
					}
				}
			}
		}
	}

	.pay {
		margin-top: 20upx;
		width: 100%;
		display: flex;
		justify-content: center;
		flex-wrap: wrap;

		.btn {
			width: 70%;
			height: 80upx;
			border-radius: 80upx;
			display: flex;
			justify-content: center;
			align-items: center;
			color: #fff;
			background-color: #f06c7a;
			box-shadow: 0upx 5upx 10upx rgba(0, 0, 0, 0.2);
		}

		.tis {
			margin-top: 10upx;
			width: 100%;
			font-size: 24upx;
			display: flex;
			justify-content: center;
			align-items: baseline;
			color: #999;

			.terms {
				color: #5a9ef7;
			}
		}
	}
</style>